<!DOCTYPE html>
<html lang="en-us">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  	<meta property="og:title" content=" python常见字符串操作 &middot;  我的博客" />
  	<meta property="og:site_name" content="我的博客" />
  	<meta property="og:url" content="/my_technology/15/" />
    
    
  	<meta property="og:type" content="article" />

    <meta property="og:article:published_time" content="2020-06-17T22:37:25&#43;08:00" />

    
    

  <title>
     python常见字符串操作 &middot;  我的博客
  </title>

    <meta name="description" content="这里是付佳康的个人博客" />

    <meta name="HandheldFriendly" content="True" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="shortcut icon" href="/my_technology/images/favicon.ico">
	  <link rel="apple-touch-icon" href="/my_technology/images/apple-touch-icon.png" />
    
    <link rel="stylesheet" type="text/css" href="/my_technology/css/screen.css" />
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400|Inconsolata" />


    
      
          <link href="/my_technology/index.xml" rel="alternate" type="application/rss+xml" title="我的博客" />
      
      
    
    <meta name="generator" content="Hugo 0.68.3" />

    <link rel="canonical" href="/my_technology/15/" />

     
</head>
<body class="nav-closed">
<div id="particles-js"></div>
  


 <div class="site-wrapper">



<header class="main-header " style="background-image: url(/my_technology/images/user.jpg)">

    <nav class="main-nav overlay clearfix">
        
            <a class="blog-logo" href="/my_technology/"><img src="/my_technology/images/user.png" alt="Blog Logo" /></a>
        
        
    </nav>
<div class="vertical">
        <div class="main-header-content inner">
            <h1 class="page-title">
              <a class="btn-bootstrap-2" href="#content">我的博客</a>
          </h1>
          <h2 class="page-description">这里是付佳康的个人博客</h2>
        </div>
</div>
    <a class="scroll-down icon-arrow-left" href="#content"><span class="hidden">Scroll Down</span></a>
</header>

  <main id="content" class="content" role="main">


  <article class="post ">

    <header class="post-header">
        <h1 class="post-title">python常见字符串操作</h1>
        <section class="post-meta">
        
         
        </section>
    </header>

    <section class="post-content">
      <pre><code>sel = &quot;ch ss arrr o&quot;
sel = sel.split()  #利用split转换成列表['ch', 'ss', 'arrr', 'o']
print(sel)
long = &quot;&quot;  #创建空字符 设为最大值
for i in sel:  # i为['ch', 'ss', 'arrr', 'o']里的数值
    if len(i)&gt;len(long): #进行长度数值的比较
        long = i  #  i的最大值 添加进 long
print(long)  #输出


index() 首页/索引  （重点） 因带克斯
ret = my_str.index(&quot;o&quot;)
print(ret)

ret = my_str.index(&quot;l&quot;,0,8) # 0，8区间 含头不含尾
print(ret)

count()查找某个字符出现次数 （重点）  抗特
ret = my_str.count(&quot;l&quot;) #区分大小写
print(ret)

replace() 替换 （重点） 瑞普累思
ret = my_str.replace(&quot;h&quot;,&quot;H&quot;,1) #若不写次数默认全部替换
print(ret)

split() 切割分割  （重点） 色普利特
ret = my_str.split(&quot; &quot;)#切割空格
print(ret)

upper() 转换mystr中的小写字母为大写 （重点）  啊盆
print(my_str.upper())

lower（） 将大写转小写 （重点） 楼窝儿
print(my_str.lower())

isalpha（） 如果mystr所有字符都是字母，则为真，否则假 （重点） 意思次普拉
ret = my_str.isalpha()  #空格也算字符
print(ret)

isdigit（） 判断是都都是数字  （重点）  意思迪G特
ret =my_str.isdigit()
print(ret)

isalnum()  如果mystr所有字符都是字母或数字则返回TRUE（真）否则假  （重点） 意思IO奶母
ret = my_str.isalnum()
print(ret)

isspace  如果mystr中《只》包含空格，则返回True，否则False  （重点） 意思思配词
ret = my_str.isspace()
print(ret)

rfind() 类似于find（）函数，不过是从右开始查找
print(my_str.find(&quot;l&quot;))  #2
print(my_str.rfind(&quot;l&quot;))   #5

capitalize()  把字符串第一个字符大写
my_str = &quot;i am a student&quot;
ret = my_str.capitalize()
print(ret)

partition() 将字符转换三部分，str前，str和str后  从左开始查找
my_str = &quot;i am a student&quot;
print(my_str.partition(&quot;am&quot;))

rpartition（） 将字符转换三部分，str前，str和str后  从右开始查找
my_str = &quot;i am a student&quot;
ret = my_str.rpartition(&quot;a&quot;)
print(ret)

splitlines() 按照行分割，返回一个包含各种作为元素的列表
my_str = &quot;i \nam a\n student&quot;
print(my_str.splitlines())

rjust()  返回一个原字符串右对齐，并使用空格填充长度  width的新字符串
ljust()  返回一个原字符串左对齐，并使用空格填充长度  width的新字符串

join 表示添加
my_str = &quot;——&quot;
list = [&quot;my&quot;,&quot;name&quot;,&quot;is&quot;,&quot;laowang&quot;]
ret = my_str.join(list)
print(ret)
</code></pre>
    </section>


  <footer class="post-footer">


    
    <figure class="author-image">

        <a class="img" href="/my_technology/" style="background-image: url(/my_technology/images/user.png)"><span class="hidden">付佳康</span></a>
    </figure>
    

    <section class="author">

  <p>付佳康</p>
  

</section>


    
    <section class="share">
      <h4>Share this page</h4>
      <a class="icon-twitter" style="font-size: 1.4em" href="https://twitter.com/share?text=python%e5%b8%b8%e8%a7%81%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%93%8d%e4%bd%9c&amp;url=%2fmy_technology%2f15%2f"
          onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
          <span class="hidden">Twitter</span>
      </a>
      <a class="icon-facebook" style="font-size: 1.4em" href="https://www.facebook.com/sharer/sharer.php?u=%2fmy_technology%2f15%2f"
          onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
          <span class="hidden">Facebook</span>
      </a>
      <a class="icon-google-plus" style="font-size: 1.4em" href="https://plus.google.com/share?url=%2fmy_technology%2f15%2f"
         onclick="window.open(this.href, 'google-plus-share', 'width=490,height=530');return false;">
          <span class="hidden">Google+</span>
      </a>
    </section>
    

    
    
    

  </footer>
</article>

</main>
    <footer class="site-footer clearfix">
        <section class="copyright"><a href="">我的博客</a> </section>
        
        <section class="poweredby">Proudly generated by <a class="icon-hugo" href="https://gohugo.io">HUGO</a>, with <a class="icon-theme" href="https://github.com/syui/hugo-theme-air">hugo-theme-air</a> theme</section>
        
    </footer>
    </div>
    <script type="text/javascript" src="/my_technology/js/jquery.js"></script>
    <script type="text/javascript" src="/my_technology/js/jquery.fitvids.js"></script>
    <script type="text/javascript" src="/my_technology/js/index.js"></script>
    <script src="/my_technology/js/particles.min.js"></script>
    <script src="/my_technology/js/particles.js"></script>  

</body>
</html>

